<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="expressionOutputFormQueryRef" :model="expressionOutputFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!expressionOutputFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="expressionOutputFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionOutputFormQuerySubmitting" @search="expressionOutputFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="expressionOutputFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="expressionOutputFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="expressionOutputFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionOutputFormQuerySubmitting" @search="expressionOutputFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="输出名称">
              <a-input v-model:value="expressionOutputFormQueryModel.outputNameAndLike" placeholder="输入输出名称" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="数据源名称">
              <a-input v-model:value="expressionOutputFormQueryModel.dsNameAndLike" placeholder="输入数据源名称" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="sql语句Id">
              <a-input v-model:value="expressionOutputFormQueryModel.sqlStrIdAndLike" placeholder="输入sql语句Id" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="描述">
              <a-input v-model:value="expressionOutputFormQueryModel.descriptionAndLike" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="expressionOutputFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="expressionOutputFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionOutputFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="expressionOutputFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="expressionOutputFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="expressionOutputFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="expressionOutputAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="expressionOutputListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionOutputUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="expressionOutputListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="expressionOutputDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="expressionOutputListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="expressionOutputDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="expressionOutputTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="expressionOutputDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="expressionOutputDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="expressionOutputListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="expressionOutputListColumns"
        :data-source="expressionOutputListDataSet"
        :loading="expressionOutputListLoading"
        :pagination="false"
        bordered
        :customRow="expressionOutputListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: expressionOutputListSelectedRowKeys, onChange: expressionOutputListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="expressionOutputListDataPage"
        v-model:pageSize="expressionOutputListDataRows"
        :total="expressionOutputListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="expressionOutputListPaginationChange"
        @showSizeChange="expressionOutputListPaginationShowSizeChange"
        v-if="expressionOutputListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!expressionOutputListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(expressionOutputListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="expressionOutputEditDrawerVisible"
      title="编辑公式输出信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="expressionOutputEditDrawerOnClose"
    >
      <a-form ref="expressionOutputFormRef" :model="expressionOutputFormModel" :rules="expressionOutputFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="输出名称" name="outputName">
              <a-input v-model:value="expressionOutputFormModel.outputName" placeholder="输入输出名称" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="数据源名称" name="dsName">
              <a-input v-model:value="expressionOutputFormModel.dsName" placeholder="输入数据源名称" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="sql语句Id" name="sqlStrId">
              <a-input v-model:value="expressionOutputFormModel.sqlStrId" placeholder="输入sql语句Id" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="描述" name="description">
              <a-input v-model:value="expressionOutputFormModel.description" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="expressionOutputFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="expressionOutputFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionOutputFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="expressionOutputFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="expressionOutputFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="expressionOutputFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="expressionOutputFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionOutputDetailDrawerVisible"
      title="公式输出详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="输出名称" :span="1">{{ expressionOutputDetailModel.outputName }}</a-descriptions-item>
          <a-descriptions-item label="数据源名称" :span="1">{{ expressionOutputDetailModel.dsName }}</a-descriptions-item>
          <a-descriptions-item label="sql语句Id" :span="1">{{ expressionOutputDetailModel.sqlStrId }}</a-descriptions-item>
          <a-descriptions-item label="描述" :span="1">{{ expressionOutputDetailModel.description }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ expressionOutputDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ expressionOutputDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionOutputDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionOutputDataImportDrawerVisible"
      title="公式输出数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="expressionOutputDataImportFileUploadRef" :fileModule="expressionOutputDataImportFileModule" @change="expressionOutputDataImportFileUploadChange" />
          <a-input v-model:value="expressionOutputDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="expressionOutputDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="expressionOutputDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="expressionOutputToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionOutputDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="expressionOutputDataImportFileModule" @change="expressionOutputDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="expressionOutputDataExportDrawerVisible"
      title="公式输出数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="expressionOutputOptionalDataExportFieldList" :selectedDataExportFieldList="expressionOutputSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="expressionOutputToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="expressionOutputToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useExpressionOutputStore } from '/@/store/modules/cn/core/kpis/expressionOutputStore'

import type { ExpressionOutput } from '/@/model/cn/core/kpis/eo/ExpressionOutput'
import { toExpressionOutput } from '/@/model/cn/core/kpis/eo/ExpressionOutput'

import type { ExpressionOutputQO } from '/@/model/cn/core/kpis/qo/ExpressionOutputQO'
import { toExpressionOutputQO } from '/@/model/cn/core/kpis/qo/ExpressionOutputQO'

import type { ExpressionOutputVO } from '/@/model/cn/core/kpis/vo/ExpressionOutputVO'
import { toExpressionOutputVO } from '/@/model/cn/core/kpis/vo/ExpressionOutputVO'

@Options({
  name: 'ExpressionOutput',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useExpressionOutputStore),
  },
})
export default class ExpressionOutput extends Vue {

  expressionOutputListDataSet: Array<ExpressionOutputVO> = []

  expressionOutputListColumns: Array<object> = [
    {
      title: '输出名称',
      dataIndex: 'outputName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '数据源名称',
      dataIndex: 'dsName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: 'sql语句Id',
      dataIndex: 'sqlStrId',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '描述',
      dataIndex: 'description',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  expressionOutputListLoading: boolean = false

  expressionOutputListSelectedRowKeys: string[] = []

  expressionOutputListSelectData: Array<ExpressionOutputVO> = []

  expressionOutputListSelectLength: number = 0

  expressionOutputListSelectCurrentRowIndex: number = -1

  expressionOutputListSelectCurrentRowData: ExpressionOutputVO = toExpressionOutputVO()

  expressionOutputListPaginationVisible: boolean = true

  expressionOutputListDataPage: number = 1

  expressionOutputListDataRows: number = 10

  expressionOutputListDataCount: number = 0

  expressionOutputListRowClickTimeout: number | null = null

  expressionOutputListRowOnChange(selectedRowKeys, selectedRows) {
    this.expressionOutputListSelectedRowKeys = [ ...selectedRowKeys ]
    this.expressionOutputListSelectData = [ ...selectedRows ]
    this.expressionOutputListSelectLength = selectedRows.length
  }

  expressionOutputListCustomRow(record, index) {
    return {
      'class': index === this.expressionOutputListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.expressionOutputListRowClickTimeout) {
          clearTimeout(this.expressionOutputListRowClickTimeout)
          this.expressionOutputListRowClickTimeout = null
        } else {
          this.expressionOutputListRowClickTimeout = setTimeout(() => {
            this.expressionOutputListRowClickTimeout = null
            this.expressionOutputListSelectCurrentRowIndex = index
            this.expressionOutputListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.expressionOutputListSelectedRowKeys ]
            let selectedRows = [ ...this.expressionOutputListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.expressionOutputListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.expressionOutputListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.expressionOutputStore.pkVo(this.$toParam<ExpressionOutputQO>({ id: record.id } as ExpressionOutputQO)).then((res: Res<ExpressionOutputVO>) => {
          if (res.succ) {
            this.expressionOutputDetailModel = { ...res.data[0] }
            this.expressionOutputDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  expressionOutputListGetDataSet() {
    this.expressionOutputListLoading = true
    this.expressionOutputListRowOnChange([], [])
    this.expressionOutputListSelectCurrentRowIndex = -1
    this.expressionOutputListSelectCurrentRowData = toExpressionOutputVO()
    this.expressionOutputStore.pagingVo(this.$toParam<ExpressionOutputQO>({ weightOrderAsc: 'y' } as ExpressionOutputQO, this.expressionOutputListDataPage, this.expressionOutputListDataRows)).then((res: Res<ExpressionOutputVO>) => {
      if (res.succ) {
        this.expressionOutputListPaginationVisible = true
        this.expressionOutputListDataSet = [ ...res.data ]
        this.expressionOutputListDataCount = res.count
        setTimeout(() => { this.expressionOutputListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionOutputListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionOutputListLoading = false }, 500)
    })
  }

  expressionOutputListPaginationChange() {
    this.expressionOutputListGetDataSet()
  }

  expressionOutputListPaginationShowSizeChange() {
    this.expressionOutputListGetDataSet()
  }

  expressionOutputFormQueryVisible: boolean = false

  expressionOutputFormQuerySubmitting: boolean = false

  expressionOutputFormQueryModel: ExpressionOutputQO = toExpressionOutputQO()

  expressionOutputFormQueryUpDown() {
    this.expressionOutputFormQueryVisible = !this.expressionOutputFormQueryVisible
  }

  expressionOutputFormQueryReset() {
    if (this.$refs.expressionOutputFormQueryRef) {
      this.$refs.expressionOutputFormQueryRef.resetFields()
      this.expressionOutputFormQueryModel = toExpressionOutputQO()
    }
  }

  expressionOutputFormQuerySearch() {
    this.expressionOutputFormQuerySubmitting = true
    this.expressionOutputListLoading = true
    this.expressionOutputListRowOnChange([], [])
    this.expressionOutputListSelectCurrentRowIndex = -1
    this.expressionOutputListSelectCurrentRowData = toExpressionOutputVO()
    this.expressionOutputStore.queryVo(this.$toParam<ExpressionOutputQO>(this.$toSearch({ ...this.expressionOutputFormQueryModel }))).then((res: Res<ExpressionOutputVO>) => {
      if (res.succ) {
        this.expressionOutputListPaginationVisible = false
        this.expressionOutputListDataSet = [ ...res.data ]
        this.expressionOutputListDataCount = res.count
        setTimeout(() => { this.expressionOutputFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionOutputListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionOutputFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionOutputListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionOutputFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.expressionOutputListLoading = false }, 500)
    })
  }

  expressionOutputEditDrawerVisible: boolean = false

  expressionOutputFormSaveSubmitting: boolean = false

  expressionOutputFormSaveContinue: boolean = false

  expressionOutputFormModel: ExpressionOutput = toExpressionOutput()

  expressionOutputFormRules: object = {
    // outputName: [
    //   { type: 'string', required: true, message: '输出名称不能为空！', trigger: ['change', 'blur'] },
    // ],
    // dsName: [
    //   { type: 'string', required: true, message: '数据源名称不能为空！', trigger: ['change', 'blur'] },
    // ],
    // sqlStrId: [
    //   { type: 'string', required: true, message: 'sql语句Id不能为空！', trigger: ['change', 'blur'] },
    // ],
    // description: [
    //   { type: 'string', required: true, message: '描述不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  expressionOutputFormReset() {
    if (this.$refs.expressionOutputFormRef) {
      this.$refs.expressionOutputFormRef.resetFields()
      this.expressionOutputFormModel = toExpressionOutput()
    }
  }

  expressionOutputFormSubmit() {
    this.expressionOutputFormSaveSubmitting = true
    this.$refs.expressionOutputFormRef.validate().then(() => {
      if (this.expressionOutputFormModel.id) {
        this.expressionOutputStore.update(this.$toParam<ExpressionOutput>(this.expressionOutputFormModel)).then((res: Res<ExpressionOutput>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionOutputFormReset()
            this.expressionOutputFormSaveSubmitting = false
            if (!this.expressionOutputFormSaveContinue) {
              this.expressionOutputEditDrawerVisible = false
              this.expressionOutputListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionOutputFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionOutputFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.expressionOutputStore.save(this.$toParam<ExpressionOutput>(this.expressionOutputFormModel)).then((res: Res<ExpressionOutput>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionOutputFormReset()
            this.expressionOutputFormSaveSubmitting = false
            if (!this.expressionOutputFormSaveContinue) {
              this.expressionOutputEditDrawerVisible = false
              this.expressionOutputListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionOutputFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionOutputFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.expressionOutputFormSaveSubmitting = false }, 3000)
    })
  }

  expressionOutputFormSave() {
    this.expressionOutputFormSaveContinue = false
    this.expressionOutputFormSubmit()
  }

  expressionOutputFormNextAdd() {
    this.expressionOutputFormSaveContinue = true
    this.expressionOutputFormSubmit()
  }

  expressionOutputAdd() {
    if (this.expressionOutputFormModel.id) {
      this.expressionOutputFormReset()
    }
    this.expressionOutputEditDrawerVisible = true
  }

  expressionOutputUpdate() {
    this.expressionOutputStore.pk(this.$toParam<ExpressionOutputQO>({ id: this.expressionOutputListSelectData[0].id } as ExpressionOutputQO)).then((res: Res<ExpressionOutput>) => {
      if (res.succ) {
        this.expressionOutputFormReset()
        this.expressionOutputFormModel = { ...res.data[0] }
        this.expressionOutputEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionOutputEditDrawerOnClose() {
    if (this.expressionOutputFormSaveContinue) {
      this.expressionOutputFormSaveContinue = false
      this.expressionOutputListGetDataSet()
    }
  }

  expressionOutputDelete() {
    let param: Array<ExpressionOutput> = []
    this.expressionOutputListSelectData.forEach((eo: ExpressionOutputVO) => {
      param.push({ id: eo.id } as ExpressionOutput)
    })
    this.expressionOutputStore.removeBatch(this.$toParam<ExpressionOutput>(param)).then((res: Res<ExpressionOutput>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.expressionOutputListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionOutputDetailDrawerVisible: boolean = false

  expressionOutputDetailModel: ExpressionOutputVO = toExpressionOutputVO()

  expressionOutputDetailInfo() {
    this.expressionOutputStore.pkVo(this.$toParam<ExpressionOutputQO>({ id: this.expressionOutputListSelectData[0].id } as ExpressionOutputQO)).then((res: Res<ExpressionOutputVO>) => {
      if (res.succ) {
        this.expressionOutputDetailModel = { ...res.data[0] }
        this.expressionOutputDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionOutputDetailUpdate() {
    this.expressionOutputStore.pk(this.$toParam<ExpressionOutputQO>({ id: this.expressionOutputDetailModel.id } as ExpressionOutputQO)).then((res: Res<ExpressionOutput>) => {
      if (res.succ) {
        this.expressionOutputFormReset()
        this.expressionOutputFormModel = { ...res.data[0] }
        this.expressionOutputDetailDrawerVisible = false
        this.expressionOutputEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionOutputTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  expressionOutputDataImportDrawerVisible: boolean = false

  expressionOutputDataImportFileSelectDrawerVisible: boolean = false

  expressionOutputDataImportFileModule: string = 'dataImport'

  expressionOutputDataImportFileUrl: string = ''

  expressionOutputDataImportSaveSubmitting: boolean = false

  expressionOutputDataImport() {
    this.expressionOutputDataImportDrawerVisible = true
  }

  expressionOutputDataImportFileUploadChange(value) {
    this.expressionOutputDataImportFileUrl = value
  }

  expressionOutputDataImportFileUrlSelectFileClick() {
    this.expressionOutputDataImportFileSelectDrawerVisible = true
  }

  expressionOutputDataImportFileSelectChange(fileUrl) {
    this.expressionOutputDataImportFileUrl = fileUrl
    this.expressionOutputDataImportFileSelectDrawerVisible = false
  }

  expressionOutputToDataImport() {
    this.expressionOutputDataImportSaveSubmitting = true
    this.expressionOutputStore.dataImport(this.$toParam<string>(this.expressionOutputDataImportFileUrl)).then((res: Res<ExpressionOutput>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.expressionOutputDataImportFileUploadRef.resetFiles()
        this.expressionOutputDataImportFileUrl = ''
        this.expressionOutputDataImportSaveSubmitting = false
        this.expressionOutputDataImportDrawerVisible = false
        this.expressionOutputListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionOutputDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionOutputDataImportSaveSubmitting = false }, 3000)
    })
  }

  expressionOutputDataExportDrawerVisible: boolean = false

  expressionOutputOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'outputName',
      fieldComment: '输出名称',
    },
    {
      fieldName: 'dsName',
      fieldComment: '数据源名称',
    },
    {
      fieldName: 'sqlStrId',
      fieldComment: 'sql语句Id',
    },
    {
      fieldName: 'description',
      fieldComment: '描述',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  expressionOutputSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  expressionOutputDataExport() {
    this.expressionOutputDataExportDrawerVisible = true
  }

  expressionOutputToDataExport(allData: boolean) {
    this.expressionOutputStore.dataExport(this.$toParam<DataExportAO<ExpressionOutputQO>>(toDataExportAO(this.expressionOutputSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as ExpressionOutputQO : this.$toSearch({ ...this.expressionOutputFormQueryModel }), '公式输出信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.expressionOutputListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
